<?php

/**
*info:杭师大报修模板
*@author:wxl
*time:2016-12-16
*/
class RepairhsdMsgtpl extends BaseMsgtpl
{
	/**
	 * 自动派单发送消息
	 * @param array $wechat		公众号信息
	 * @param array $order		订单信息
	 * @param array $repairman	维修工
	 * @return
	 */
	public function autoOperateSendMsg($order,$repairman,$accountId)
	{
		$wechatUserInfo = D('Wechat/WechatUser')->getInfo(array('user_id' => $repairman), 'openid,subscribe,wechat_id');
		$url = C('site_url')."/repairhsd/repairhsdReceive/index/repairId/".$order['repair_id']."/order_id/".$order['order_id'];
		if($accountId == 2){
			$template_id = 'D3IHmxcLckGTHiXw-LDlApX9VIWdOvcZgVqyunmESjo';
		}elseif($accountId == 5){
			$template_id = '4EeswD5oYCEQJi2u8AOzAQrflX5aCQVxFOcr592-fvY';
		}elseif($accountId == 6){
			$template_id = 'y2OZQJsNL3wXLOrbTuXzuX2x5IVT_ZDsLodN3Mpzyug';
		}elseif($accountId == 4){  //测试服
			$template_id = 'k203JXlZ8F8SCYUIR3uH_HBL8Uq2aAMbAIv2N1r46ec';
		}elseif($accountId == 10){  //铁道部
			$template_id = 'RUdkrbYCT4fM8eYiEzMGoFrdj7tM2g9YI_Px4xaxETU';
		}elseif($accountId == 28){
			$template_id = '_hHj0eU1ZQ7yorFomzpQvFV21NxQj8S_bqolOO9sbBk';
		}elseif($accountId == 3){
			$template_id = 'Xip28HCL4EbvNB6bItDLrIheQnOceLI87-ZDE5f4m0A';
		}elseif($accountId == 17){
			$template_id = 'nr3BnPPtM-TA11B537yEf9_CRIV9KXbL9wn7lDJxWFg';
		}elseif($accountId == 22){
			$template_id = 'F-qFB-UE6XsmlvpM5liaOwXOLmuaTUosK7A_pz7im9o';
		}elseif($accountId == 7){
			$template_id = 'ldaz0ckkWWq0iNp65KPycuNVEZYYcXtUvRHbwiOWfGs';
		}

		//if($wechatUserInfo && $wechatUserInfo['subscribe']){
            if($accountId == 22 || $accountId == 7){
            	$projectName = '';
            	if($order['project_id']){
            		$projectInfo = D('Repairhsd/RepairhsdProject')->getByProjectId($order['project_id']);
            		$projectName = $projectInfo['project_name'];
            	}
            	$childProject = '';
            	if($order['project_child_id']){
            		$childInfo = D('Repairhsd/RepairhsdProject')->getByProjectId($order['project_child_id']);
            		$childProject = ' '.$childInfo['project_name'];
            	}
            	
            	$projects = $projectName?$projectName.($childProject?$childProject:''):'-';
            	$info = array(
	                'first' => array("value" => '您有新的派单，请在您的维修广场查看！','color' => '#173177'),
	                'keyword1' => array("value" => $order['real_name'] ),
	                'keyword2' => array("value" => $order['content'] ),
	                'keyword3' => array("value" => $projects ),
	                'keyword4' => array("value" => $order['community_name'].$order['building_name'].$order['room_name'].$order['detail_address'] ),
	                'keyword5' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
	                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            	);
            }
            else{
            	$info = array(
	                'first' => array("value" => '您有新的派单，请在您的维修广场查看！','color' => '#173177'),
	                'keyword1' => array("value" => $order['real_name'] ),
	                'keyword2' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
	                'keyword3' => array("value" => date('Y-m-d H:i:s',strtotime("+1 hour")),"color" => "#173177" ),
	                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            	);
            }
            

            $result = $this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $wechatUserInfo['openid'], $template_id, $info, $url);
            return $result;
		//}

		return false;
	}
	
	/**
	 * 方法参数可以自己修改，添加
	 * @param array $userData	用户信息
	 * @param array $orderInfo	订单信息
	 */
	public function orderConfirmSendMsg($orderId,$accountId)
	{
		$mOrder = D('RepairhsdOrder');
		$mUser = D('Base/User');
		$orderInfo = $mOrder->getByOrderId($orderId);
		$repairman = $mUser->getByPk($orderInfo['repairman_id']);
		$wechatUserInfo = D('Wechat/WechatUser')->getInfo(array('user_id'=>$orderInfo['user_id']), 'openid,subscribe');
		$url = C('site_url').'/index.php?g=repairhsd&m=repairhsdUserOrder&a=userOrderDetail&repairId='.$orderInfo['repair_id'].'&order_id='.$orderInfo['order_id'];
		//if($wechatUserInfo['subscribe']) {
			if($accountId != 4){
				$array = array(
						'first' => array("value" => $orderInfo['real_name'].'，您的维修申请已经通过。','color' => '#173177'),
						'keyword2' => array("value" => $repairman['real_name'] ),
						'keyword1' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
						'remark' => array("value" => "请点击查看！","color" => "#173177"),
				);
			}else{
				$array = array(
						'first' => array("value" => $orderInfo['real_name'].'，您的维修申请已经通过。','color' => '#173177'),
						'keyword1' => array("value" => '订单号'.$orderInfo['order_sn'] ),
						'keyword2' => array("value" => date("Y-m-d H:i:s")),
						'keyword3' => array("value" => '123456' ),
						'remark' => array("value" => "您有新的派单，请点击查看！","color" => "#173177"),
				);
			}
			
			
			if($accountId == 2){
				$template_id = 'ervBp_BlUtHqKsaIw0qjmFz2KXy9J1tWCF5TIhW042Q';
			}elseif($accountId==5){
				$template_id = 'p_P3GalanUy8syyholudeTR3OB5hzEuEAz-w12D_lbQ';
			}elseif($accountId==6){
				$template_id = 'DAxDdnfAhywT-lfRTsaSGOQwd96g5RQnXMTigQknWCA';
			}elseif($accountId == 4){
				$template_id = 'k203JXlZ8F8SCYUIR3uH_HBL8Uq2aAMbAIv2N1r46ec';
			}elseif($accountId == 10){
				$template_id = 'A4NBwXw1VQmYDOBzCImVstEnwLG2tvbkztK8vbJkc-I';
			}elseif($accountId == 28){
				$template_id = 'Rf7JatKFZNlX-Fji4e2AmRwCvffF8bCsUxdnsHCHAZs';
			}elseif($accountId==3){
				$template_id = 'yI0d_ILucYN4r_4lfnqsvwUOPd94K7Se7rQkUScaEiU';
			}elseif($accountId == 17){
				$template_id = 'qV44STOD0tpw_b2JHWrV7TsBk3uYdjpuCIYSp5gJqb4';
			}elseif($accountId == 22){
				$template_id = 'WiguocN3goznC5lVyB4yw100e_wrEvISvoFGHStUhN0';
			}elseif($accountId == 7){
				$template_id = '44Z68YQ3QP5YtatYHElODM5iKzNBrNnI552eiY4drSE';
			}
			$this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $wechatUserInfo['openid'], $template_id, $array, $url);
		//}
			
	}
	
	/**
	 * 订单完成处理
	 * @param array $userData
	 * @param array $orderInfo
	 */
	public function orderFinishSendMsg($orderInfo,$accountId)
	{
		$mUser = D('Base/User');
		$repairman = $mUser->getFieldByUserId($orderInfo['repairman_id'],'real_name');
		$wechatUserInfo = D('Wechat/WechatUser')->getInfo(array('user_id'=>$orderInfo['user_id']), 'openid,subscribe');
		//$url = C('site_url')."/base/repair/orderDetail/repairId/".$orderInfo['repair_id']."/order_id/".$orderInfo['order_id'];
		$url = C('site_url').'/index.php?g=repairhsd&m=repairhsdUserOrder&a=userOrderDetail&repairId='.$orderInfo['repair_id'].'&order_id='.$orderInfo['order_id'];
		//if($wechatUserInfo['subscribe']) {
			if($orderInfo['pay_type'] == 1 && $orderInfo['pay_time'] == 0) {
				$array = array(
					'first' => array("value" => $orderInfo['real_name'].'，您的维修已经完成,维修金额'.$orderInfo['order_amount'].'元，请尽快完成支付！','color' => '#173177'),
					'keyword2' => array("value" => $repairman ),
					'keyword1' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
					'remark' => array("value" => "请点击查看！","color" => "#173177"),
				);
			} else {
				$array = array(
					'first' => array("value" => $orderInfo['real_name'].'，您的维修已经完成。','color' => '#173177'),
					'keyword2' => array("value" => $repairman ),
					'keyword1' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
					'remark' => array("value" => "请点击查看！","color" => "#173177"),
				);
			}

			if($accountId == 2){
				$template_id = 'ervBp_BlUtHqKsaIw0qjmFz2KXy9J1tWCF5TIhW042Q';
			}elseif($accountId==5){
				$template_id = 'p_P3GalanUy8syyholudeTR3OB5hzEuEAz-w12D_lbQ';
			}elseif($accountId==6){
				$template_id = 'DAxDdnfAhywT-lfRTsaSGOQwd96g5RQnXMTigQknWCA';
			}elseif($accountId == 4){
				$template_id = 'k203JXlZ8F8SCYUIR3uH_HBL8Uq2aAMbAIv2N1r46ec';
			}elseif($accountId == 10){
				$template_id = 'A4NBwXw1VQmYDOBzCImVstEnwLG2tvbkztK8vbJkc-I';
			}elseif($accountId == 28){
				$template_id = 'Rf7JatKFZNlX-Fji4e2AmRwCvffF8bCsUxdnsHCHAZs';
			}elseif($accountId==3){
				$template_id = 'yI0d_ILucYN4r_4lfnqsvwUOPd94K7Se7rQkUScaEiU';
			}elseif($this->wechatInfo['account_id'] == 17){
				$template_id = 'qV44STOD0tpw_b2JHWrV7TsBk3uYdjpuCIYSp5gJqb4';
			}elseif($accountId == 22){
				$template_id = 'WiguocN3goznC5lVyB4yw100e_wrEvISvoFGHStUhN0';
			}elseif($accountId == 7){
				$template_id = '44Z68YQ3QP5YtatYHElODM5iKzNBrNnI552eiY4drSE';
			}
			$result = $this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $wechatUserInfo['openid'], $template_id, $array, $url);
			return $result;
		//}
		return false;
	}



	/**
	 * 维修工无法维修提交返修,发消息给用户
	 * @param array $userData	用户信息
	 * @param array $orderInfo	订单信息
	 */
	/*public function backSendMessage($order,$accountId)
	{
		$mOrder = D('RepairOrder');
		$mUser = D('User');
		$orderInfo = $mOrder->getByPk($order['order_id']);
		$repairman = $mUser->getByPk($orderInfo['repairman_id']);
		$wechatUserInfo = D('Wechat/WechatUser')->getInfo(array('user_id'=>$orderInfo['user_id']), 'openid,subscribe');
		$url = C('site_url').'/index.php?g=base&m=repair&a=orderDetail&repairId='.$orderInfo['repair_id'].'&order_id='.$orderInfo['order_id'];
		if($wechatUserInfo['subscribe']) {

				$array = array(
						'first' => array("value" => $orderInfo['real_name'].'，您的维修单已提交返修,请确认并重新下单。','color' => '#FF0000'),
						'keyword2' => array("value" => $repairman['real_name'] ),
						'keyword1' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
						'remark' => array("value" => "请点击查看！","color" => "#173177"),
				);
			
			
			
			if($accountId == 2){
				$template_id = 'ervBp_BlUtHqKsaIw0qjmFz2KXy9J1tWCF5TIhW042Q';
			}elseif($accountId==5){
				$template_id = 'p_P3GalanUy8syyholudeTR3OB5hzEuEAz-w12D_lbQ';
			}elseif($accountId==6){
				$template_id = 'DAxDdnfAhywT-lfRTsaSGOQwd96g5RQnXMTigQknWCA';
			}elseif($accountId == 4){
				$template_id = 'k203JXlZ8F8SCYUIR3uH_HBL8Uq2aAMbAIv2N1r46ec';
			}elseif($accountId == 10){
				$template_id = 'A4NBwXw1VQmYDOBzCImVstEnwLG2tvbkztK8vbJkc-I';
			}elseif($accountId == 28){
				$template_id = 'Rf7JatKFZNlX-Fji4e2AmRwCvffF8bCsUxdnsHCHAZs';
			}elseif($accountId==3){
				$template_id = 'yI0d_ILucYN4r_4lfnqsvwUOPd94K7Se7rQkUScaEiU';
			}elseif($this->wechatInfo['account_id'] == 17){
				$template_id = 'qV44STOD0tpw_b2JHWrV7TsBk3uYdjpuCIYSp5gJqb4';
			}
			$this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $wechatUserInfo['openid'], $template_id, $array, $url);
		}
			
	}*/
	
// 	/**
// 	 * 创建订单完成后发送短信
// 	 * @param array $userData	用户信息
// 	 * @param array $orderInfo	订单信息
// 	 */
// 	public function createOrderSendMsg($userData, $orderInfo)
// 	{
// 		//todo...
// 	}
	
// 	/**
// 	 * 订单评论发送消息
// 	 * @param array $userData	用户信息
// 	 * @param array $orderInfo 订单信息
// 	 */
// 	public function orderCommentSendMsg($userData, $orderInfo)
// 	{
// 		//todo...
// 	}
}
